package com.sugon.controller.device;

import com.sugon.modules.device.model.DevMaintenPlanItemVO;
import com.sugon.modules.device.model.vo.DevMaintenancePlanDeviceVO;
import com.sugon.service.DevMaintenancePlanItemService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 设备维护计划项信息Controller
 *
 * @author sugon
 * @date 2020-07-26 20:00:49
 */
@Controller
@RequestMapping("devplanmainitem")
public class DevPlanMainItemController {
    @Autowired
    private DevMaintenancePlanItemService devMaintenancePlanItemService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {

        //查询列表数据
        Query query = new Query(params);

        List<DevMaintenPlanItemVO> devPlanMainItemList = devMaintenancePlanItemService.queryList(query);
        int total = devMaintenancePlanItemService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devPlanMainItemList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看设备维护计划中指定维护频率下的设备维护项列表
     *
     * @param params
     * @return
     */
    @RequestMapping("/listDev")
    @ResponseBody
    public R listDev(@RequestParam Map<String, Object> params) {
        List<DevMaintenancePlanDeviceVO> devPlanMainItemList = devMaintenancePlanItemService.queryDevList(params);
        PageUtils pageUtil = new PageUtils(devPlanMainItemList, devPlanMainItemList.size(), 1000, 1);
        return R.ok().put("page", pageUtil);
    }

}
